<?php
// +----------------------------------------------------------------------
// | [ DO WHAT YOU LOVE AND FUCK THE REST ]
// +----------------------------------------------------------------------
// | Author 荒年 < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 管理员用户名
// +----------------------------------------------------------------------
namespace app\admin\validate;

class Admin extends BaseValidate
{
  protected $rule = [
    'username' => 'require|unique:admin|alphaNum|length:4,26|Initials',
    'tel' => 'mobile|unique:admin',
    'group_id' => 'require',
  ];

  protected $message = [
    'group_id.require' => '角色不能为空',
    'username.require' => '用户名不能为空',
    'username.alphaNum' => '用户名只能为字母和数字',
    'username.length' => '用户名长度为4到26个字符',
    'username.unique' => '用户名不能重复',
    'username.Initials' => '用户名首位必须为字母',
    'tel.mobile' => '手机号格式不正确',
    'tel.unique' => '手机号已经被绑定',
  ];


  //正整数验证
  protected function Initials($value)
  {
    $data = [ 'user'  => substr($value, 0, 1) ];
    $validate = \think\facade\Validate::rule('user', 'alpha');
    if ($validate->check($data)) {
      return true;
    }
    else {
      return false;
    }
  }

}
?>